package com.oocl.listener;

import java.util.List;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import com.oocl.db.FoodTypeDB;
import com.oocl.pojo.FoodType;
import com.oocl.service.FoodService;
import com.oocl.service.impl.FoodServiceImpl;

/**
 * Application Lifecycle Listener implementation class MyServletContextListener
 *
 */
public class FoodTypeListener implements ServletContextListener {
	public static String realPath;
	
    /**
     * Default constructor. 
     */
    public FoodTypeListener() {
        // TODO Auto-generated constructor stub
    }

	/**
     * @see ServletContextListener#contextInitialized(ServletContextEvent)
     */
    public void contextInitialized(ServletContextEvent sce) {
    	System.out.println("food type/.................");
    	realPath = sce.getServletContext().getRealPath("/");
    	FoodService foodManager = new FoodServiceImpl();
    	List<FoodType> foodTypes = foodManager.findFoodTypes();
    	
    	for(FoodType foodType:foodTypes){
    		FoodTypeDB.getFoodTypes().put(foodType.getId(), foodType.getName());
    	}
    	sce.getServletContext().setAttribute("AllFoodTypes", foodTypes);
    	System.out.println(FoodTypeDB.getFoodTypes().toString());
    }

	/**
     * @see ServletContextListener#contextDestroyed(ServletContextEvent)
     */
    public void contextDestroyed(ServletContextEvent arg0) {
        // TODO Auto-generated method stub
    }
	
}
